/*
 * 文件名：RealsocksUser.java
 * 版权：亚信联创版权所有
 * 描述：TODO
 * 修改人：yuanze
 * 修改时间：2014年11月1日
 * 修改内容：TODO
 */
package com.ailk.bigdata.etl.realstream.server.model;

import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.ailk.bigdata.etl.common.server.annotations.Column;
import com.ailk.bigdata.etl.common.server.annotations.Id;
import com.ailk.bigdata.etl.common.server.annotations.Table;
import com.ailk.bigdata.etl.common.server.encrypt.EncryptUtil;

/**
 * @description 实时采集用户管理
 * @author [yuanze]
 * @version [版本号,2014年11月1日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Table(name = "td_realsocks_user")
public class RealsocksUser
{
	@Id(name = "real_id")
	private String realId;// 实时采集编码
	@Column(name = "real_system_id")
	private int realSystemId;// 实时系统编码
	@Column(name = "user_acct")
	private String userAcct;// 用户账号
	@Column(name = "real_user_pwd")
	private String realUserPwd;// 用户密码
	@Column(name = "max_connect")
	private int maxConnect;// 最大连接数
	@Column(name = "session_time")
	private int sessionTime;// 会话时间
	@Column(name = "user_type")
	private int userType;// 用户类型
	private long timestamp;
	private int rand;

	public String getRealId()
	{
		return realId;
	}

	public void setRealId(String realId)
	{
		this.realId = realId;
	}

	public int getRealSystemId()
	{
		return realSystemId;
	}

	public void setRealSystemId(int realSystemId)
	{
		this.realSystemId = realSystemId;
	}

	public String getUserAcct()
	{
		return userAcct;
	}

	public void setUserAcct(String userAcct)
	{
		this.userAcct = userAcct;
	}

	public String getRealUserPwd()
	{
		return realUserPwd;
	}

	public void setRealUserPwd(String realUserPwd)
	{
		this.realUserPwd = realUserPwd;
	}

	public int getMaxConnect()
	{
		return maxConnect;
	}

	public void setMaxConnect(int maxConnect)
	{
		this.maxConnect = maxConnect;
	}

	public int getSessionTime()
	{
		return sessionTime;
	}

	public void setSessionTime(int sessionTime)
	{
		this.sessionTime = sessionTime;
	}

	public int getUserType()
	{
		return userType;
	}

	public void setUserType(int userType)
	{
		this.userType = userType;
	}

	public long getTimestamp()
	{
		return timestamp;
	}

	public void setTimestamp(long timestamp)
	{
		this.timestamp = timestamp;
	}

	public int getRand()
	{
		return rand;
	}

	public void setRand(int rand)
	{
		this.rand = rand;
	}

	public String getDigest()
	{
	    String formatDigest = "";
		try
		{
			EncryptUtil encryptUtil = EncryptUtil.getInstance();
			
			MessageDigest messageDigest = null;
			byte[] hash = null;
			messageDigest = MessageDigest.getInstance("SHA-256");
			messageDigest.reset();
			
			//SimpleDateFormat format = new SimpleDateFormat();
			//format.applyPattern("MMddHHmmss");
			formatDigest = userAcct + "         " 
					+ encryptUtil.encryptSHA256(encryptUtil.decryptBASE64(realUserPwd))
					+ timestamp + "rand=" + rand;
			hash = messageDigest.digest(formatDigest.getBytes("UTF-8"));
			StringBuilder sb = new StringBuilder();
			for(int i=0;i<hash.length;i++) {
				sb.append(String.format("%02X", hash[i]));
			}
			formatDigest = sb.toString();
		}
		catch (Exception e)
		{
		}
		return formatDigest;
	}

}
